<?php
	class Admin extends CI_Controller
	{
		public function __construct()
		{
			parent::__construct();
			$this->load->Model("model_admin");
			$this->load->helper(array("my_data"));
			
		}
		public function index(){
			$user = $this->session->userdata("tendangnhap");
			//$this->session->userdata("quyen","admin");
			if(empty($user))
			{
				redirect("admin/admin/login");
			}
			if($this->session->userdata("quyen")=='admin')
			{
			$data["title"] ="Trang chủ";
			$data1['item'] = $this->model_admin->thongtincanhan_admin($user);
			//$data2["lists"] = $this->Events_model->allevents();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/trangchu",$data1);
			$this->load->view("admin/footer");
			}
		}
		
		public function checkvalue_tendangnhap_signin()
		{
			$ten_tk =$this->input->post('admin_tendn_signin');
			if($this->model_admin->admin_check_username($ten_tk)){ 
			
              echo "<img src='".base_url()."image/admin/cancel.png' />";		  
            } 
			else
			{
				echo "<img src='".base_url()."image/admin/accept.png' />";
			}
		}
		public function checkvalue_email_signin()
		{
			$email =$this->input->post('admin_email_signin');
			if($this->model_admin->admin_check_email($email)){ 
			
              echo "<img src='".base_url()."image/admin/cancel.png' />";		  
            } 
			else
			{
				echo "<img src='".base_url()."image/admin/accept.png' />";
			}
		}
		public function login(){
			$user = $this->session->userdata("tendangnhap");
			if($user)
			{
				$this->thoat();
			}
			
			$data["title"] ="Đăng nhập";

			$this->load->view("admin/login", $data);
		}
		public function signin(){
			$user = $this->session->userdata("tendangnhap");
			if($user)
			{
				$this->thoat();
			}
			$data["title"] ="Đăng ký";

			$this->load->view("admin/signin", $data);
		}
		
		public function insert_signin(){
			$this->load->library('form_validation');
		if($this->form_validation->run('signin')==false)
		{
			$this->signin();	
		}
		else
		{
			$message = "";
			$ten_tk =$this->input->post('admin_tendn_signin');
			$mat_khau = $this->input->post('admin_matkhau_signin');
			$mat_khau_encode=$this->encrypt->encode($this->input->post('admin_matkhau_signin'),'nhi');
			$day = $this->input->post('sltNgay');
			$month = $this->input->post('sltThang');
			$year = $this->input->post('sltNam');
			$strdate=$year."-".$month."-".$day;
			$ngaysinh=date("y-m-j", strtotime($strdate));
			$email = $this->input->post('admin_email_signin');
			$ma_kich_hoat = create_random_string(5);			
					
			if(!$this->model_admin->admin_check_username($ten_tk))
			{
				if(!$this->model_admin->admin_check_email($email))
				{
					$data = array
					(
						'ten_tk'=> $this->input->post('admin_tendn_signin'),
						'mat_khau'=>$this->encrypt->encode($this->input->post('admin_matkhau_signin'),'nhi'),
						'quyen' => 1,
						'ho_ten' => $this->input->post('admin_hoten_signin'),
						'ngay_sinh' => $ngaysinh,
						'gioi_tinh' => $this->input->post('rdGioiTinh'),
						'dia_chi' => $this->input->post('admin_diachi_signin'),
						'email' => $this->input->post('admin_email_signin'),
						'sdt' => $this->input->post('admin_sodienthoai_signin'),
						'cmnd' => $this->input->post('admin_cmnd_signin'),
						'trang_thai' => 1,
						'active_email' => 0,	
						'ma_kich_hoat'=> $ma_kich_hoat,			
					);
					$this->model_admin->insert_signin($data);
					$link_active = base_url()."index.php/admin/admin/active_email/?ten_tk=".$ten_tk."&ma_kich_hoat=".md5($ma_kich_hoat);
					$message  = "Vui lòng click vào link bên dưới để kích hoạt tài khoản của bạn <br/>".
					$message .= "Link : <a href=".$link_active.">".$link_active."</a><br/>";
					$message .= "Tên tài khoản : ".$ten_tk."<br/>";
					$message .= "Mật khẩu : ".$mat_khau;
	
					$mail = array(
							"to_receiver"   => $this->input->post('admin_email_signin'),
							"message"       => $message,
						);
	
					$this->load->library("my_email");
					$this->my_email->config($mail);
					$this->my_email->sendmail();
					echo "<script> alert('Đăng ký thành công! Vui lòng kiểm tra email để kích hoạt tài khoản') </script>";
					$this->login();
				}
				else
				{
					redirect("admin/admin/signin");
				}
			}
			else
			{
				redirect("admin/admin/signin");
			}
		}
		}
		public function active_email()
		{
			$user = $this->session->userdata("tendangnhap");
			//--- Neu Login thi khong active
			if($this->session->userdata("tendangnhap"))
			{
				redirect("admin/admin/login");
				echo "<script> alert('Đang đăng nhập, vui lòng đăng nhập lại') </script>";
				$this->login();
			}
			$ten_tk = $_GET['ten_tk'];
			$ma_kich_hoat = $_GET['ma_kich_hoat'];
			$check = $this->model_admin->checkActive($ten_tk,$ma_kich_hoat);
            if($check){
                
                if($check['active_email']==1)
                {
                   /* $data['report'] = "Account has been actived, <a href='".base_url()."home/verify/login'>please login</a> !";*/
                    echo "<script> alert('Tài khoản của bạn đã được kích hoạt! Vui lòng đăng nhập') </script>";
					$this->login();
                }
                else
                {                    
                     $update = array(
                             "active_email" => 1,
                                );
                    $this->model_admin->capnhat_tk_active($ten_tk,$update);
                    echo "<script> alert('Tài khoản của bạn đã được kích hoạt! Vui lòng đăng nhập') </script>";
					$this->login();   
                }
            
            }
            else{
                $data['report'] = "Your account not avaliable !";
            }
		}
		public function signin_kiemtra($Username, $Password)
		{
		
			$taikhoan_admin = $this->model_admin->tk_admin($Username,$Password);
			
			if(isset($taikhoan_admin) && !empty($taikhoan_admin->ten_tk))
			{
				$this->session->set_userdata("tendangnhap",$taikhoan_admin->ten_tk);
				$this->session->set_userdata("matkhau",$taikhoan_admin->mat_khau);
				$this->session->set_userdata("hoten",$taikhoan_admin->ho_ten);
				$this->session->set_userdata("quyen",'admin');		
				redirect("admin/admin/index");
			}
			
		}
		public function login_kiemtra() //Kiểm tra dữ liệu khi login
		{
			$Username = $this->input->post('admin_tendn_login');
			$Password = $this->input->post('admin_matkhau_login');	
			if($this->model_admin->admin_check_username($Username))
			{		
				$taikhoan_admin = $this->model_admin->tk_admin($Username);
				if(!empty($taikhoan_admin->mat_khau))
				{
					$str = $this->encrypt->decode($taikhoan_admin->mat_khau,'nhi');
					if($Password == $str)
					{
						if(isset($taikhoan_admin) && !empty($taikhoan_admin->ten_tk))
						{
							//$quyen = $_POST['quyen'];
							$this->session->set_userdata("tendangnhap",$taikhoan_admin->ten_tk);
							$this->session->set_userdata("matkhau",$taikhoan_admin->mat_khau);
							$this->session->set_userdata("hoten",$taikhoan_admin->ho_ten);
							$this->session->set_userdata("quyen",'admin');
							//$this->session->set_userdata("quyen",$quyen);
							redirect("admin/admin/index");
						}
					}
					else
					{						
						echo "<script> alert('Đăng nhập thất bại, sai password') </script>";
						$this->login(); 
					}
				}
				else
				{	
					
					echo "<script> alert('Đăng nhập thất bại, vui lòng kích hoạt email') </script>";
					$this->login();  
				}
			}
			else
			{
				echo "<script> alert('Đăng nhập thất bại, không tồn tại tên đăng nhập') </script>";
				$this->login();  
			}
		}
		public function thoat()
		{
			$this->session->sess_destroy();
			redirect('admin/admin/login');
		}
		public function forgotpass(){
			$user = $this->session->userdata("tendangnhap");
			if($user)
			{
				$this->thoat();
			}
			
			$data["title"] ="Lấy lại mật khẩu";

			$this->load->view("admin/forgotpass", $data);
		}
		public function forgotpass_sendemail()
		{
			$message = "";
			$tendangnhap = $this->input->post('admin_tendn_forgotpass');
			$email = $this->input->post('admin_email_forgotpass');
			$taikhoan_admin = $this->model_admin->admin_check_email_username($tendangnhap,$email);
					
			if($this->model_admin->admin_check_email_username($tendangnhap,$email))
			{
				$link_active = base_url()."index.php/admin/admin/login";
				$password = $this->encrypt->decode($taikhoan_admin->mat_khau,'nhi');
				$sendtendangnhap=$taikhoan_admin->ten_tk;
				$message  = "Thông tin đăng nhập của bạn :<br/>";
                $message .= "Tên đăng nhập :".$sendtendangnhap."<br/>";
                $message .= "Mật khẩu:".$password."<br/>";				
				$message  = "Vui lòng click vào link bên dưới để đăng nhập vào dongthaptourist <br/>".
				$message .= "Link : <a href=".$link_active.">".$link_active."</a><br/>";
                
                $mail = array(
                            "to_receiver"   => $email,
                            "message"       => $message,
                        );

                $this->load->library("my_email");
                $this->my_email->config_forgot($mail);
                $this->my_email->sendmail_forgot();
				echo "<script> alert('Kiểm tra email của bạn để đăng nhập lại') </script>";
				$this->login();
			}
			else
			{
				echo "<script> alert('Sai tên đăng nhập hoặc email') </script>";
				$this->forgotpass();
			}
			
		}
		public function doimatkhau()
		{
			$user = $this->session->userdata("tendangnhap");
			//$this->session->userdata("quyen","admin");
			if(empty($user))
			{
				redirect("admin/admin/login");
			}
			if($this->session->userdata("quyen")=='admin')
			{
			$data["title"] ="Đổi mật khẩu";
			
			//$data2["lists"] = $this->Events_model->allevents();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/doimatkhau");
			$this->load->view("admin/footer");
			}
		}
		public function doimatkhau_luu()
		{
			$user = $this->session->userdata("tendangnhap");
			if(empty($user)){
				redirect("admin/admin/login");
			}
			else
			{
				$this->load->library('form_validation');
				if($this->form_validation->run('doimatkhau')==false)
				{
					$this->doimatkhau();
					echo "<script> alert('Validate k dc') </script>";	
				}
				else
				{
					$data1 = array(
			           'matkhaucu'=> $this->input->post('admin_matkhaucu_doimatkhau'),
					   'nhaplaimatkhau' =>$this->input->post('admin_nhaplaimatkhaumoi_doimatkhau')
								);
					$matkhaumoi = $this->input->post('admin_matkhaumoi_doimatkhau');
					$data2['matkhaumoi']=$this->input->post('admin_matkhaumoi_doimatkhau');
					$data3= $this->model_admin->laypass_theotentk($user);
					if ((strcasecmp($data1['matkhaucu'],$this->encrypt->decode($data3->mat_khau,'nhi'))==0) and (strcasecmp($data2['matkhaumoi'],$data1['nhaplaimatkhau'])==0))
					{
						$update = array(
                             "mat_khau" => $this->encrypt->encode($matkhaumoi,'nhi'),
                                );
						$this->model_admin->update_matkhau($user,$update);
						echo "<script> alert('Đổi mật khẩu thành công') </script>";
						$this->index();
						
					}
					else 
					{ 
						echo "<script> alert('Đổi mật khẩu thất bại') </script>";
						$this->doimatkhau();
					}
				}
			}
		}
		public function capnhatthongtin()
		{
			$user = $this->session->userdata("tendangnhap");
			//$this->session->userdata("quyen","admin");
			if(empty($user))
			{
				redirect("admin/admin/login");
			}
			if($this->session->userdata("quyen")=='admin')
			{
			$data["title"] ="Cập nhật thông tin";
			$data2["item"] = $this->model_admin->infor_bytentk($user);
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/capnhatthongtincanhan", $data2);
			$this->load->view("admin/footer");
			}
		}
		public function qlmenu(){
			$data["title"] ="Quản lý menu";
			
			//$data2["lists"] = $this->Events_model->allevents();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/qlmenu");
			$this->load->view("admin/footer");
		}
		public function qltttb(){
			$data["title"] ="Tin tức - Thông báo";
			
			//$data2["lists"] = $this->Events_model->allevents();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/qltttb");
			$this->load->view("admin/footer");
		}
		public function qltour(){
			$data["title"] ="Quản lý tour";
			
			//$data2["lists"] = $this->Events_model->allevents();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/qltour");
			$this->load->view("admin/footer");
		}
		public function qlchuyendi(){
			$data["title"] ="Quản lý chuyến đi";
			
			//$data2["lists"] = $this->Events_model->allevents();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/qlchuyendi");
			$this->load->view("admin/footer");
		}
		public function qlkhachsan(){
			$data["title"] ="Quản lý khách sạn";
			
			//$data2["lists"] = $this->Events_model->allevents();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/qlkhachsan");
			$this->load->view("admin/footer");
		}
<<<<<<< .mine
		/*-----------------------------------------------------QUAN CHUYEN DI-----------------------------------------------*/
		/*-----------------------------------------------------QUAN LY KHACHSAN---------------------------------------------*/
		public function qlkhachsan($currentPage=0){
			$data["title"] ="Quản lý khách sạn";
			$data1["number"] = $this->model_admin->number_khachsan();	
			$this->load->library('pagination');
			$config['base_url'] = base_url()."index.php/admin/admin/qlkhachsan";
			$config['total_rows'] = $data1["number"];
			$config['per_page'] = 25;
			$config['num_links'] = 2;
			$this->pagination->initialize($config);
			$data1["paging"] = $this->pagination->create_links(); 
			$data1["item"] = $this->model_admin->ds_khachsan($currentPage, $config['per_page']);
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/qlkhachsan",$data1);
			$this->load->view("admin/footer");
		}
		public function tao_khachsanmoi(){
			$data["title"] ="Tạo khách sạn mới";
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/tao_khachsanmoi");
			$this->load->view("admin/footer");
		}
		function do_upload_khachsan($field_name)
		{
			$config['upload_path']  = './image/khachsan/';
			$config['allowed_types'] = 'gif|jpg|png|jpeg';
			$config['max_size'] = '30000'; //kilobytes
			$config['max_width'] = '1024';
			$config['max_height'] = '768';
			$this->load->library('upload', $config);
			if ( ! $this->upload->do_upload($field_name))
			{
				$error = array('error' => $this->upload->display_errors());
				return $error;
			}
			else
			{
				$data = $this->upload->data();
				return $data;
			}
		}
		function do_upload_khachsan_listhinhanh($field_name)
		{
				$config['upload_path']  = './image/khachsan/';
				$config['allowed_types'] = 'gif|jpg|png|jpeg';
				$config['max_size'] = '30000'; //kilobytes
				$config['max_width'] = '1024';
				$config['max_height'] = '768';
				$this->load->library('upload', $config);
				print_r($item);
				if ( !$this->upload->do_multi_upload($field_name))
				{
					$error = array('error' => $this->upload->display_errors());
					return $error;
				}
				else
				{
					$data = array('data'=>$this->upload->data());
					return $data;
				}
		}
		public function themmoi_khachsan()
		{
			$user = $this->session->userdata("tendangnhap");
			if(empty($user)){
				redirect("admin/admin/login");
			}
			if($this->session->userdata("quyen")=='admin')
			{
				/*$this->load->library('form_validation');				
				if($this->form_validation->run('khachsanmoi')==false)
				{
					$this->tao_khachsanmoi();	
				}
				else
				{		*/	
					$upload_result =$this->do_upload_khachsan_listhinhanh('admin_khachsan_listfileHinhAnh[]');
					$this->data['upload_result'].=$upload_result;
					echo "<pre>";
					print_r($upload_result);
					echo "</pre>";
					$result=true;					
					$hinhanh=$upload_result['file_name'];
					echo "<pre>";
					print_r($hinhanh);
					echo "</pre>";
					/*if($result==true)
					{
						$this->resize($upload_result["full_path"]);
							$data = array
							(
								'ten_khachsan'=> $this->input->post('admin_tenkhachsan_tao_khachsanmoi'),
								'dia_chi'=> $this->input->post('admin_diachi_tao_khachsanmoi'),
								'tinh'=>$this->input->post('admin_tinh_tao_khachsanmoi'),
								'xep_hang' => $this->input->post('admin_xephang_tao_khachsanmoi'),
								'sdt' => $this->input->post('admin_sdt_tao_khachsanmoi'),
								'email' => $this->input->post('admin_email_tao_khachsanmoi'),
								'website' => $this->input->post('admin_website_tao_khachsanmoi'),
								'mo_ta' => $this->input->post('admin_noidung_tao_tttbmoi'),
								'hinh_dai_dien' =>  $hinhanh,
								'trang_thai' => 1,
							);
							
							$this->model_admin->insert_khachsan($data);
							$id= $this->model_admin->id_khachsan_vua_insert();
							//redirect("admin/admin/infor_byidkhachsan/".$id->id_khachsan);
							redirect("admin/admin/qlkhachsan");
							echo "<script>alert('Thêm thanh cong')</script>";
					}
						else
						{
							echo "<script>alert('Thêm thất bại')</script>";	
							$this->tao_khachsanmoi();
						}

				}*/
			}
		}
		function chitiet_khachsan($idkhachsan)
		{
			$user = $this->session->userdata("tendangnhap");
			if(empty($user)){
				redirect("admin/admin/login");
			}
			if($this->session->userdata("quyen")=='admin')
			{
			$data["title"] ="Chi tiết khách sạn";
			$data1 = $this->model_admin->chitiet_khachsan($idkhachsan);
			print_r($data1);
			/*$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/chitiet_khachsan", $data1);
			$this->load->view("admin/footer");*/
			}
		}
		public function sua_khachsan($id)
		{
			$user = $this->session->userdata("tendangnhap");
			if(empty($user))
			{
				redirect("admin/admin/login");
			}
			if($this->session->userdata("quyen")=='admin')
			{
			$data["title"] ="Sửa khách sạn";
			$data1["item2"] = $this->model_admin->infor_byidkhachsan($id);
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/sua_khachsan",$data1);
			$this->load->view("admin/footer");
			}
		}
		public function update_khachsan($idkhachsan)
		{
			$user = $this->session->userdata("tendangnhap");
			if(empty($user)){
				redirect("admin/admin/login");
			}
			if($this->session->userdata("quyen")=='admin')
			{
				$this->load->library('form_validation');
				if($this->form_validation->run('suakhachsan')==false)
				{
					redirect("admin/admin/capnhat_tttb");
					echo "<script>alert('Chua validation')</script>";
				}
				else
				{
					$hinhanhks = $this->input->post('admin_khachsan_fileHinhAnh_sua');
					$upload_result=$this->do_upload_khachsan('admin_khachsan_fileHinhAnh_sua');
					$this->data['upload_result']=$upload_result;
					$hinhanh=$upload_result['file_name'];
					$result=true;
					if($result==true)
					{
						if($hinhanh!="")
						{
							$data = array
							(
								'ten_khachsan'=> $this->input->post('admin_tenkhachsan_sua_khachsan'),
								'dia_chi'=> $this->input->post('admin_diachi_sua_khachsan'),
								'tinh'=>$this->input->post('admin_tinh_sua_khachsan'),
								'xep_hang' => $this->input->post('admin_xephang_sua_khachsan'),
								'sdt' => $this->input->post('admin_sdt_sua_khachsan'),
								'email' => $this->input->post('admin_email_sua_khachsan'),
								'website' => $this->input->post('admin_website_sua_khachsan'),
								'mo_ta' => $this->input->post('admin_noidung_sua_khachsan'),
								'hinh_dai_dien' =>  $hinhanh,
								'trang_thai' => $this->input->post('admin_trangthai_sua_khachsan'),
							);
							
							$this->model_admin->update_khachsan($idkhachsan,$data);
							//redirect("admin/admin/chitiet_khachsan/".$idkhachsan);
							redirect("admin/admin/qlkhachsan");
							echo "<script>alert('Sửa thành công')</script>";
						}
						else
						{
							$data1 = array
							(
								'ten_khachsan'=> $this->input->post('admin_tenkhachsan_sua_khachsan'),
								'dia_chi'=> $this->input->post('admin_diachi_sua_khachsan'),
								'tinh'=>$this->input->post('admin_tinh_sua_khachsan'),
								'xep_hang' => $this->input->post('admin_xephang_sua_khachsan'),
								'sdt' => $this->input->post('admin_sdt_sua_khachsan'),
								'email' => $this->input->post('admin_email_sua_khachsan'),
								'website' => $this->input->post('admin_website_sua_khachsan'),
								'mo_ta' => $this->input->post('admin_noidung_sua_khachsan'),
								'trang_thai' => $this->input->post('admin_trangthai_sua_khachsan'),
							);
							$this->model_admin->update_khachsan($idkhachsan,$data1);
							redirect("admin/admin/qlkhachsan");
							//redirect("admin/admin/chitiet_khachsan/".$idkhachsan);
							echo "<script>alert('Sua thanh cong')</script>";
						}
					}
					else
					{
						$this->sua_khachsan($idkhachsan);
					}
				}

			}
		}
		public function delete_khachsan($idkhachsan)
		{
			$user = $this->session->userdata("tendangnhap");
			if(empty($user)){
				redirect("admin/admin/login");
			}
			if($this->session->userdata("quyen")=='admin')
			{
				$this->model_admin->delete_khachsan($idkhachsan);
				redirect("admin/admin/qlkhachsan");
			}
		}
		/*-----------------------------------------------------QUAN LY KHACHSAN---------------------------------------------*/
		/*-----------------------------------------------------QUAN LY KHUYENMAI---------------------------------------------*/
=======
>>>>>>> .r106
		public function qlkhuyenmai(){
			$data["title"] ="Quản lý khuyến mãi";
			
			//$data2["lists"] = $this->Events_model->allevents();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/qlkhuyenmai");
			$this->load->view("admin/footer");
		}
		public function qlnguoidung(){
			$data["title"] ="Quản lý người dùng";
			
			//$data2["lists"] = $this->Events_model->allevents();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/qlnguoidung");
			$this->load->view("admin/footer");
		}
		public function xemphanhoi(){
			$data["title"] ="Xem phản hồi";
			
			//$data2["lists"] = $this->Events_model->allevents();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/xemphanhoi");
			$this->load->view("admin/footer");
		}
<<<<<<< .mine

/*-------------------Xem don dat hang-------------*/

		/*-----------------------------------------------------QUAN LY XEM PHAN HOI---------------------------------------------*/
		/*-----------------------------------------------------QUAN LY DON DAT HANG---------------------------------------------*/

=======
>>>>>>> .r106
		public function xemddh(){
			$data["title"] ="Xem đơn đặt hàng";
			
			//$data2["lists"] = $this->Events_model->allevents();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/xemddh");
			$this->load->view("admin/footer");
		}
<<<<<<< .mine
		public function tim_khuyenmai(){
			
			
			$checbox =$this->input->post('ckbtinhtrang');
				if($checbox=="on")
				{
					$data["title"] ="Quản lý khuyến mãi";
			
			$data1["item"] = $this->admin_model->tk_khuyenmai();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/qlkhuyenmai",$data1);
			$this->load->view("admin/footer");
					
				}
				else
				$this->qlkhuyenmai();
				
		}
		public function them_khuyenmai(){
			$data["title"] ="Thêm khuyến mãi";
			
			//$data1["item"] = $this->admin_model->xem_khuyenmai();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/themkm");
			$this->load->view("admin/footer");
		}
		public function check_insert(){
			
			
			$ngaybatdau=$this->input->post("txtngaybd");
			$ngayketthuc=$this->input->post("txtngaykt");
			if (strtotime($ngayketthuc) > strtotime($ngaybatdau)) 
			{
			$data1 = array(
				'tieu_de'=>$this->input->post("txttieude"),
				'ngay_bat_dau'=>$this->input->post("txtngaybd"),
				'ngay_ket_thuc'=>$this->input->post("txtngaykt"),
				'ty_le'=>$this->input->post("txttile"),
				'so_luong'=>$this->input->post("txtsoluong"),
				'trang_thai'=>1
			);
			 $this->admin_model->them_khuyenmai($data1);
			 echo "<script> alert('Thêm khuyến mãi thành công') </script>";
			$this->qlkhuyenmai();
			}
			else
			{
				 echo "<script> alert('Ngày bắt đầu phải nhỏ hơn ngày kết thúc') </script>";
				$this->qlkhuyenmai();
			}
		}
		public function suakhuyenmai($id){
			$data["title"] ="Sửa thông tin khuyến mãi";
			
			$data1["item"] = $this->admin_model->get_khuyenmai($id);
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/suakhuyenmai",$data1);
			$this->load->view("admin/footer");
		}
		public function check_update($id){
			$data["title"] ="Sửa thông tin khuyến mãi";
			$ngaybatdau=$this->input->post("txtngaybd");
			$ngayketthuc=$this->input->post("txtngaykt");
			if (strtotime($ngayketthuc) > strtotime($ngaybatdau)) 
			{
				$data1 = array(
					'tieu_de'=>$this->input->post("txttieude"),
					'ngay_bat_dau'=>$this->input->post("txtngaybd"),
					'ngay_ket_thuc'=>$this->input->post("txtngaykt"),
					'ty_le'=>$this->input->post("txttile"),
					'so_luong'=>$this->input->post("txtsoluong"),
					'trang_thai'=>1
				);
				$this->admin_model->sua_khuyenmai($id,$data1);
				$this->qlkhuyenmai();
			}
			else
			{
				 echo "<script> alert('Ngày bắt đầu phải nhỏ hơn ngày kết thúc') </script>";
				$this->suakhuyenmai();
			}
			
		}
		
		public function xoa_khuyenmai($id){
			$user = $this->session->userdata("tendangnhap");
			$this->session->userdata("quyen","admin");
			if(empty($user))
			{
				redirect("admin/admin/login");
			}
			if($this->session->userdata("quyen")=='admin')
			{
				$data['trang_thai']= 0;
				$this->admin_model->xoa_khuyenmai($id,$data);
				$this->qlkhuyenmai();
				
				
			}
		}
/*-------------------Quan ky hoa don-------------*/

		/*-----------------------------------------------------QUAN LY DON DAT HANG---------------------------------------------*/
		/*-----------------------------------------------------QUAN LY HOA DON---------------------------------------------*/

=======
>>>>>>> .r106
		public function qlhdon(){
			$data["title"] ="Quản lý hóa đơn";
			
			//$data2["lists"] = $this->Events_model->allevents();
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/qlhdon");
			$this->load->view("admin/footer");
		}
<<<<<<< .mine
		public function tk_hoadon()
		{
			$data["title"] ="Tìm kiếm hóa đơn";
			$hoten=$this->input->post("txttimkiem");
			$data1["item"] = $this->admin_model->tk_hoadonkh($hoten);
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/timkiem_hd",$data1);
			$this->load->view("admin/footer");
		}
		public function xemddh_hd1($ten_tk)
		{
			$data["title"] ="Quản lý hóa đơn";
			$data1["item"] = $this->admin_model->xemddh_hd($ten_tk);
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/qlhdon",$data1);
			$this->load->view("admin/footer");
		}
/*-------------------Lap hoa don-------------*/
		public function laphoadon(){
			$user = $this->session->userdata("tendangnhap");
			$this->session->userdata("quyen","admin");
			if(empty($user))
			{
				redirect("admin/admin/login");
				}
=======
		
			}
>>>>>>> .r106
<<<<<<< .mine
			if($this->session->userdata("quyen")=='admin')
			{
				$data["title"] ="Lập hóa đơn";
				$data1["item"] = $this->admin_model->kh_chuatt();
				$this->load->view("admin/header", $data);
				$this->load->view("admin/menutrai");
				$this->load->view("admin/laphoadon",$data1);
				$this->load->view("admin/footer");
			}
		}

		/*-----------------------------------------------------QUAN LY HOA DON---------------------------------------------*/
		/*-----------------------------------------------------QUAN LY---------------------------------------------*/
		
		public function tkddh_hd()
		{
			$data["title"] ="Lập hóa đơn";
			$hoten=$this->input->post("txttimkiem");
			$data1["item"] = $this->admin_model->timkiem_khachhang($hoten);
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/qlhdon",$data1);
			$this->load->view("admin/footer");
		}
		public function xemddh_hd($ten_tk)
		{
			$data["title"] ="Quản lý hóa đơn";
			$data1["item"] = $this->admin_model->xemddh_hd($ten_tk);
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/xemddh_hd",$data1);
			$this->load->view("admin/footer");
		}
		public function xemchitiet_ddh($id_ddh)
		{
			$data["title"] ="Quản lý hóa đơn";
			$data1["item"] = $this->admin_model->xemchitiet_ddh($id_ddh);
			$this->load->view("admin/header", $data);
			$this->load->view("admin/menutrai");
			$this->load->view("admin/xemchitiet_ddh",$data1);
			$this->load->view("admin/footer");
		}
			}
=======
>>>>>>> .r106
?>